﻿using duia.Canteenpay.Domain;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using System;

namespace duia.Canteenpay.Repository.EntityConfiguration
{
    /// <summary>
    /// EF配置基类KeyId
    /// </summary>
    /// <typeparam name="TEntity"></typeparam>
    public class BaseEntityKeyIdTypeConfiguration<TEntity> : IEntityTypeConfiguration<TEntity> where TEntity : BaseEntityId
    {
        public virtual void Configure(EntityTypeBuilder<TEntity> builder)
        {
            builder.HasKey(x => x.KeyId);
        }
    }

    /// <summary>
    /// EF配置基类
    /// </summary>
    /// <typeparam name="TEntity"></typeparam>
    public class BaseEntityTypeConfiguration<TEntity> : IEntityTypeConfiguration<TEntity> where TEntity : BaseEntity
    {
        public virtual void Configure(EntityTypeBuilder<TEntity> builder)
        {
            builder.HasKey(x => x.KeyId);
            builder.Property(x => x.CreateTime).HasDefaultValue(DateTime.Now);
            builder.Property(x => x.CreateUserKeyId);
            builder.Property(x => x.CreateUserName).HasMaxLength(50);
            builder.Property(x => x.IsDelete).HasDefaultValue(false);
            builder.Property(x => x.UpdateTime).HasDefaultValue(DateTime.Now);
            builder.Property(x => x.UpdateUserName).HasMaxLength(50);
            builder.Property(x => x.UpdateUserKeyId);
        }
    }
}
